/**
 * tip控件
 */
var CustomTip = ccui.Layout.extend({

    contentText: "",

    tipPanel: null,

    spacing: 20,

    ctor: function () {
        this._super();
        this.tipPanel = null;
        this.setTouchEnabled(true);
        this.addTouchEventListener(this.onTouch.bind(this));
    },

    onTouch: function (sender, type) {
        switch (type) {
            case ccui.Widget.TOUCH_BEGAN:
                this.showTip();
                break;
            case ccui.Widget.TOUCH_CANCELED:
            case ccui.Widget.TOUCH_ENDED:
                this.hideTip();
                break;
        }
    },

    showTip: function () {
        if (this.tipPanel == null) {
            var text = new ccui.Text();
            text.setFontSize(26);
            text.setTextColor(cc.color("#ffffffff"));
            text.setString(this.contentText);
            var textSize = text.getContentSize();
            this.tipPanel = new ccui.Layout();
            this.tipPanel.setAnchorPoint(cc.p(0.5, 0.5));
            this.tipPanel.setBackGroundImageScale9Enabled(true);
            this.tipPanel.setBackGroundImage(createRoom.res.popupBack1_png);
            this.tipPanel.setContentSize(cc.size(textSize.width + this.spacing, textSize.height + this.spacing));
            this.tipPanel.addChild(text);
            this.parent.addChild(this.tipPanel);
            var panelSize = this.tipPanel.getContentSize();
            var postion = cc.p(this.x - panelSize.width / 2, this.y + panelSize.height / 2);
            if (postion.x - panelSize.width / 2 < 0) {
                postion.x = panelSize.width / 2;
            }
            if (postion.y + panelSize.height / 2 > this.parent.getContentSize().height) {
                postion.y = this.parent.getContentSize().height - panelSize.height / 2;
            }
            this.tipPanel.setPosition(postion);
            text.setPosition(cc.p(panelSize.width / 2, panelSize.height / 2));
        }
        this.tipPanel.show();
    },

    hideTip: function () {
        if (this.tipPanel != null) {
            this.tipPanel.hide();
        }
    }
});